package com.shilin.watchsystem.service.exception.impl;

import com.shilin.watchsystem.enums.ResultEnum;
import com.shilin.watchsystem.exception.AppException;
import com.shilin.watchsystem.service.exception.ExceptionService;
import org.springframework.stereotype.Service;

@Service
public class ExceptionServiceImpl implements ExceptionService {

    public void throwException(ResultEnum resultEnum) {
        throw new AppException(resultEnum);
    }

    public void throwException(Integer code, String message) {
        throw new AppException(code, message);
    }



    /**
     * 空异常
     * @param object
     */
    public void throwNullException(Object object) {

        if (object == null) {
            throw new AppException(ResultEnum.PARAM_NULL);
        }
    }

    @Override
    public void throwNullPointException(Object object, Class t) {
        if(object == null){
            throw new AppException(555,t.getName()+"空异常");
        }
    }


    /**
     * 非equals异常
     * @param source
     * @param target
     * @param resultEnum
     */
    public void throwNotEqualsException(Object source, Object target, ResultEnum resultEnum) {
        if (!source.equals(target)) {
            throw new AppException(resultEnum);
        }
    }
}
